import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/material.dart';
import 'package:flutter_demo/core/common/utils/image_utils.dart';
import 'package:flutter_demo/core/common/values/gaps.dart';
import 'package:flutter_demo/ui/pages/treasure/module/course_item.dart';
import 'package:flutter_demo/ui/pages/treasure/widgets/title_widget.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

// ignore: must_be_immutable
class ArticleWidget extends StatelessWidget {
  int index;
  CourseItem courseList;
  ArticleWidget(this.courseList, {super.key, required this.index});

  @override
  Widget build(BuildContext context) {
    return Container(
        margin: EdgeInsets.only(left: 20.w, right: 20.w),
        //color: Colors.black.withOpacity(0.1),
        child: Column(children: [
          if (index == 0)
            TitleWidget(
              title: "精品文章  ",
              buttonTitle: "更多",
            ),
          if (index == 0) Gaps.vGap10,
          Row(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              ClipRRect(
                  borderRadius: BorderRadius.circular(6),
                  child: CachedNetworkImage(
                    imageUrl: courseList.imageUrl!,
                    color: const TextStyle().color,
                    fit: BoxFit.cover,
                    width: 98.w,
                    height: 75.h,
                  )),
              Gaps.hGap10,
              SizedBox(
                height: 75.h,
                child: Column(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      Text(
                        courseList.title!,
                        maxLines: 2,
                        overflow: TextOverflow.ellipsis,
                      ),
                      Column(
                        crossAxisAlignment: CrossAxisAlignment.start,
                        children: [
                          Text("价格:${courseList.price}"),
                          Text.rich(
                            TextSpan(children: [
                              WidgetSpan(
                                child:
                                    Image.asset(ImageUtils.getImagePath('ca_'),
                                        fit: BoxFit.cover,
                                        //color: Colors.black,
                                        width: 14.w,
                                        height: 14.h),
                              ),
                              TextSpan(
                                text: courseList.popularity,
                              ),
                            ]),
                            maxLines: 1,
                            overflow: TextOverflow.ellipsis,
                          )
                        ],
                      ),
                    ]),
              )
            ],
          ),
          Gaps.line20,
        ]));
  }
}
